package com.itheima.myutil.myexception;

import java.util.Scanner;

public class Demo {
    public static void main(String[] args) {
        Student stu = new Student();
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入姓名：");
        String name = sc.nextLine();
        stu.setName(name);
        while (true) {
            try {
                System.out.println("请输入年龄：");
                String ageStr = sc.nextLine();
                Integer age = Integer.valueOf(ageStr);
                stu.setAge(age);
                break;
            } catch (NumberFormatException e) {
                System.out.println("录入的年龄必须是整数");
            } catch (_AgeOutOfException e) {
                System.out.println("年龄必须在18到255岁之间");
            }
        }
        System.out.println(stu);
    }
}
